package 早餐组合;

import java.util.Arrays;

public class Solution {
    public int breakfastNumber(int[] staple, int[] drinks, int x) {

        Arrays.sort(staple);
        Arrays.sort(drinks);
        int res = 0;
        int i = 0;
        int j = drinks.length -1;
        while(i < staple.length && j >= 0){
            if(staple[i] + drinks[j] <= x){
                res += j+1;
                i++;
            }
            else{
                j--;
            }
        }
        return res;
    }
}
